﻿using Common;
using Logic;
using Model;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;

namespace AppAdmin.Controllers
{
    public class ItemsDataController : ControllerBase
    {

        [HttpGet]
        public ActionResult GetGridJson(string itemId, string keyword)
        {
            var data =new ItemsDataLogic().GetList(itemId, keyword);
            return Content(data.ToJson());
        }
        [HttpGet]
        public ActionResult GetSelectJson(string enCode)
        {
            var data = new ItemsDataLogic().GetItemList(enCode);
            List<object> list = new List<object>();
            foreach (Sys_ItemsDetail item in data)
            {
                list.Add(new { id = item.F_ItemCode, text = item.F_ItemName });
            }
            return Content(list.ToJson());
        }
        [HttpGet]
        public ActionResult GetFormJson(string keyValue)
        {
            var data = new ItemsDataLogic().GetForm(keyValue);
            return Content(data.ToJson());
        }
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitForm(Sys_ItemsDetail itemsDetailEntity, string keyValue)
        {
            new ItemsDataLogic ().SubmitForm(itemsDetailEntity, keyValue);
            return  Content(new AjaxResult { state = ResultType.success.ToString(), message = "操作成功。" }.ToJson()); 
        }
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteForm(string keyValue)
        {
            new ItemsDataLogic().DeleteForm(keyValue);
            return  Content(new AjaxResult { state = ResultType.success.ToString(), message = "删除成功。" }.ToJson()); 
        }
    }
}
